home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / LIB / VALIDCMD.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  4KB  |  102 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    v a l i d c m d . c                                             */
  3. /*                                                                    */
  4. /*    Security routines for UUPC/extended                             */
  5. /*                                                                    */
  6. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  7. /*    See README.PRN for additional copyrights and restrictions       */
  8. /*--------------------------------------------------------------------*/
  9.  
  10. /*--------------------------------------------------------------------*/
  11. /*                        System include files                        */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <sys/types.h>        /* Only really needed for MS C         */
  18. #include <sys/stat.h>
  19. #include <time.h>
  20.  
  21. /*--------------------------------------------------------------------*/
  22. /*                    UUPC/extended include files                     */
  23. /*--------------------------------------------------------------------*/
  24.  
  25. #include "lib.h"
  26. #include "hostable.h"
  27. #include "security.h"
  28. #include "usertabl.h"
  29. #include "expath.h"
  30. #include "hlib.h"
  31.  
  32. currentfile();
  33. /*--------------------------------------------------------------------*/
  34. /*    V a l i d a t e C o m m a n d                                   */
  35. /*                                                                    */
  36. /*    Determine if a command is allowed for a host                    */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. boolean ValidateCommand( const char *command)
  40. {
  41.    char **p;
  42.  
  43. /*--------------------------------------------------------------------*/
  44. /*                Validate the security table is okay                 */
  45. /*--------------------------------------------------------------------*/
  46.  
  47.    if ( securep == NULL )
  48.       panic();
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*                        Handle local system                         */
  52. /*--------------------------------------------------------------------*/
  53.  
  54.    if ( securep->local )      /* Local system?                       */
  55.    {
  56.  
  57. #ifdef UDEBUG
  58.       printmsg( 5, "ValidateCommand: Local system, command \"%s\" allowed",
  59.             command );
  60. #endif
  61.  
  62.       return TRUE;            /* Yes --> Bless the request           */
  63.    }
  64.  
  65. /*--------------------------------------------------------------------*/
  66. /*     Loop through security command table looking for the target     */
  67. /*--------------------------------------------------------------------*/
  68.  
  69.    p = securep->commands;
  70.    while (*p != NULL)
  71.    {
  72.       boolean global;
  73.  
  74. #ifdef UDEBUG
  75.       printmsg(10,"ValidateCommand: Comparing \"%s\" to \"%s\"",
  76.                *p, command );
  77. #endif
  78.  
  79.       if equal(*p, ANY_COMMAND )
  80.          global = TRUE;
  81.       else
  82.          global = FALSE;
  83.  
  84.       if (global || equali(*p, command ))
  85.       {
  86.          printmsg(5,"ValidateCommand: Command \"%s\" %splicitly allowed",
  87.                   command, global ? "im" : "ex" );
  88.          return TRUE;
  89.       }
  90.       p++ ;
  91.    } /* while */
  92.  
  93. /*--------------------------------------------------------------------*/
  94. /*               We didn't find the command; reject it                */
  95. /*--------------------------------------------------------------------*/
  96.  
  97.    printmsg(5,"ValidateCommand: Command \"%s\" not allowed",
  98.             command );
  99.    return FALSE;
  100.  
  101. } /* ValidateCommand */
  102.